class Symbol {
  constructor() {
    this.symbolMap = new Map();
    this.initDefaultSymbols();
  }

  initDefaultSymbols() {
    Array(16)
      .fill('')
      .forEach((item, index) => {
        this.symbolMap.set('R' + index, index);
      });
    this.symbolMap.set('SP', 0);
    this.symbolMap.set('LCL', 1);
    this.symbolMap.set('ARG', 2);
    this.symbolMap.set('THIS', 3);
    this.symbolMap.set('THAT', 4);
    this.symbolMap.set('SCREEN', 16384);
    this.symbolMap.set('KBD', 24576);
  }

  addEntry(symbol, address) {
    this.symbolMap.set(symbol, address);
  }

  contains(symbol) {
    return this.symbolMap.has(symbol);
  }

  getAddress(symbol) {
    return this.symbolMap.get(symbol);
  }
}

module.exports.Symbol = Symbol;